package com.itheima.chapter10.paralleltools.semaphore;

import java.util.concurrent.Semaphore;

public class MyRunnable implements Runnable{
    //允许通过最大线程
    private Semaphore semaphore =new Semaphore(2);

    @Override
    public void run() {
        try {
            semaphore.acquire();
            System.out.println("获得通行证，开始通行");
            Thread.sleep(10000);
            System.out.println("归还通行证");
            semaphore.release();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
